<template>
	<view :style="colorStyle">
		<view class='commission-details'>
			<view class='promoterHeader bg-color'>
				<view class='headerCon acea-row row-between-wrapper'>
					<view>
						<view class="acea-row" style="align-items: center;">
							<view>我的股份</view>
							<view class='money'>￥{{userInfo.stocks||0}}</view>
						</view>

						<view class="acea-row" style="align-items: center;">
							<view>总分红金额</view>
							<view class='money'>￥{{userInfo.stock_price||0}}</view>
						</view>
					</view>
					<view class='iconfont icon-jinbi1'></view>
				</view>
			</view>

			<view class="nav acea-row row-around">
				<view class="item" :class="orderStatus == 0 ? 'on' : ''" @click="statusClick(0)">
					<view>股份获得记录</view>
				</view>
				<view class="item" :class="orderStatus == 1 ? 'on' : ''" @click="statusClick(1)">
					<view>分红记录</view>
				</view>
			</view>

			<view class='sign-record' v-if="orderStatus==0">
				<block v-for="(item,index) in recordList" :key="index" v-if="recordList.length>0">
					<view class='list'>
						<view class='item'>
							<view class='listn'>
								<view class='itemn acea-row row-between-wrapper'>
									<view>
										<view class='name line1'>{{item.comment}}</view>
										<view>{{item.created_at}}</view>
									</view>
									<view class='num font-color' v-if="item.change_action == 1">+{{item.num}}</view>
									<view class='num' v-else>-{{item.num}}</view>
								</view>
							</view>
						</view>
					</view>
				</block>
				<view v-if="recordList.length == 0">
					<emptyPage title='暂无提现记录~'></emptyPage>
				</view>

				<view class="loadingicon acea-row row-center-wrapper">
					<!-- <text class="loading iconfont icon-jiazai" :hidden="loading == false"></text> -->
					我也是有底线的~~~
				</view>
			</view>

			<view class='sign-record' v-if="orderStatus==1">
				<block v-for="(item,index) in dividend" :key="index" v-if="dividend.length>0">
					<view class='list'>
						<view class='item'>
							<view class='listn'>
								<view class='itemn acea-row row-between-wrapper'>
									<view>
										<view class='name line1'>{{pay_type[item.pay_type]}}</view>
										<view>到账时间{{item.play_with_time}}</view>
									</view>

									<view class='num font-color'>
										<view>{{order_status[item.order_status]}}</view>
										<view>金额:{{item.pay_price}}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
				<view v-if="dividend.length == 0">
					<emptyPage title='暂无提现记录~'></emptyPage>
				</view>

				<view class="loadingicon acea-row row-center-wrapper">
					<!-- <text class="loading iconfont icon-jiazai" :hidden="loading == false"></text> -->
					我也是有底线的~~~
				</view>
			</view>






		</view>

		<!-- #ifndef MP -->
		<home></home>
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		getUserInfo,
		getStocksDividend,
		getStocksRecord
	} from '@/api/user.js';
	import {
		mapGetters
	} from "vuex";

	import emptyPage from '@/components/emptyPage.vue'
	import home from '@/components/home';
	import colors from '@/mixins/color.js';
	// #ifdef MP
	import authorize from '@/components/Authorize';
	// #endif
	export default {
		components: {
			// #ifdef MP
			authorize,
			// #endif
			emptyPage,
			home
		},
		mixins: [colors],
		data() {
			return {
				orderStatus: 0,
				recordList: [],
				dividend: [],
				userInfo: {},
				pageRecord: 1,
				limitRecord: 10,
				pageDividend: 1,
				limitDividend: 10,
				order_status: ['审核中', '待打款', '审核失败', '打款成功', '打款失败'],
				pay_type: ['', '微信', '支付宝', '银行卡']
			};
		},
		onShow: function() {
			this.getUserInfo()
			this.getList()
			uni.setNavigationBarTitle({
				title: "股东"
			});
		},
		methods: {
			getUserInfo: function() {
				let that = this;
				getUserInfo().then(res => {
					console.log(res)
					that.userInfo = res.data
				});
			},
			getList() {
				switch (this.orderStatus) {
					case 0:
						this.stocksRecord(this.pageRecord, this.limitRecord);
						break;
					case 1:
						this.stocksDividend(this.pageDividend, this.limitDividend)
						break;
				}
			},
			/**
			 * 股份获得记录
			 */
			stocksRecord(page, limit) {
				console.log(page, 'page,page,page,')
				getStocksRecord({
					page,
					limit
				}).then(res => {
					if (res.data.length > 0) {
						let list = res.data || [];
						this.recordList = this.$util.SplitArray(list, this.recordList);
						this.$set(this, 'recordList', this.recordList);
						this.pageRecord = this.pageRecord + 1
					}

					console.log(this.recordList, 'getStocksDividend')
				})
			},
			/**
			 * 分红记录
			 */
			stocksDividend(page, limit) {
				console.log(page, 'page,page,page,')
				getStocksDividend({
					page,
					limit
				}).then(res => {
					if (res.data.length > 0) {
						let list = res.data || [];
						this.dividend = this.$util.SplitArray(list, this.dividend);
						this.$set(this, 'dividend', this.dividend);
						this.pageDividend = this.pageDividend + 1
						console.log(res, 'stocksDividendstocksDividend')
					}
				})
			},

			/**
			 * 切换类型
			 */
			statusClick(status) {
				if (status == this.orderStatus) return;
				this.orderStatus = status;
				this.$set(this, 'recordList', []);
				this.$set(this, 'dividend', []);
				this.$set(this, 'pageRecord', 1);
				this.$set(this, 'pageDividend', 1);
				this.getList();
			}
		},
		onReachBottom: function() {
			this.getList();
		}
	}
</script>

<style scoped lang="scss">
	.sign-record {
		margin-top: 20rpx;
	}

	.commission-details .promoterHeader .headerCon .money {
		font-size: 36rpx;
	}

	.commission-details .promoterHeader .headerCon .money .num {
		font-family: 'Guildford Pro';
	}

	.nav {
		background-color: #fff;
		width: 690rpx;
		border-radius: 6rpx;
		margin: -30rpx auto 0 auto;
	}


	.nav .item {
		text-align: center;
		font-size: 26rpx;
		color: #282828;
		padding: 27rpx 0;
		border-bottom: 5rpx solid transparent;
	}

	.nav .item.on {
		/* #ifdef H5 || MP */
		font-weight: bold;
		/* #endif */
		/* #ifdef APP-PLUS */
		color: #000;
		/* #endif */
		border-color: var(--view-theme);
	}

	.nav .item .num {
		margin-top: 18rpx;
	}
</style>
